package com.bee.剑指offer;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-04-18
 */
public class 数组中重复的数字 {

    public int duplicate(int[] numbers) {
        // write code here
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] < 0 || numbers[i] > numbers.length - 1) {
                return -1;
            }
            if (list.contains(numbers[i])) {
                return numbers[i];
            } else {
                list.add(numbers[i]);
            }
        }
        return -1;
    }


    public static void main(String[] args) {

    }
}
